package product;

import java.util.HashMap;
import java.util.Map;

public class OrderProcessor {
    private HashMap<String, Product> products = new HashMap<>();

    public void addProduct(Product product) {
        products.put(product.getId(), product);
    }

    public void processOrder(String productId,int quantity)throws Exception{
        Product product = products.get(productId);
        if (product == null) {
            throw new Exception("商品不存在");
        }
        product.reduceInventory(quantity);
        System.out.println("订单处理成功:" + product);
    }

}
